const Controller = require('egg').Controller;


class LoginController extends Controller {
    // 登录
    async index() {
        const { ctx } = this;
        var data = await ctx.service.login.login(ctx.request.body);
        const { code, msg, id } = data;
        console.log(id, msg, code);
        if (code == 200) {
            ctx.cookies.set('userID', id, {
                httpOnly: false    //# 服务器端设置cookie让客户端可读
            })
        }
        ctx.body = {
            code,
            msg,
            id,
        }
    };
    // 登出
    async out() {
        const { ctx } = this;
        ctx.cookies.set('userID', '', {
            httpOnly: false    //# 服务器端设置cookie让客户端可读
        })
        ctx.body = {
            code:200,
            msg:"退出登录"
        }
    }
}

module.exports = LoginController;